package com.idig8.leetcode.链表;

import java.util.HashMap;
import java.util.Stack;

/**
 * @program: java-show
 * @description: ${description}
 * @author: LiMing
 * @create: 2020-05-06 11:08
 **/
public class _20_有效的括号 {

    private HashMap<Character,Character> map = new HashMap<>();

    public _20_有效的括号(){
        map.put('(',')');
        map.put('[',']');
        map.put('{','}');
    }
    /**
     * 栈的方式来分析有效的括号
     * @param s
     * @return
     */
    public boolean isValid_stack(String s) {
        Stack<Character> stack = new Stack<>();
       String[] strings={};
       int length = strings.length;
        int len =s.length();
        for (int i = 0 ;i<len;i++){
            char c = s.charAt(i);
            if(map.containsKey(c)){
                stack.push(c);
            }else{
                if(stack.isEmpty()){return false;}
                char left = stack.pop();
                if(c !=map.get(stack.pop())) return false;
            }
        }
        return stack.isEmpty();
    }
//    /**
//     * 字符串的方式进行校验
//     * @param s
//     * @return
//     */
//    public boolean isValid(String s) {
//        while(s.contains("()")||s.contains("{}")||s.contains("[]")){
//            s = s.replace("()","");
//            s = s.replace("{}","");
//            s = s.replace("[]","");
//        }
//        return s.isEmpty();
//    }
}
